package com.agency8x.validator;

import com.agency8x.web.util.ValidatorUtil;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * AdminValidator.
 */
public class AdminValidator extends Validator {

	protected void validate(Controller controller) {
		this.setShortCircuit(true);
		Integer user_id = controller.getParaToInt("user_id");
		if (null == user_id) {
			validateRequiredString("user_name", "userNameMsg", "请输入用户名!");
		}
		validateRequiredString("password", "passwordMsg", "请输入登录密码!");
	}

	protected void handleError(Controller controller) {
		ValidatorUtil.errorRedirect(controller, new String[] { "user_name", "password" });
		/*
		 * controller.keepModel(AdminModel.class);
		 * 
		 * String actionKey = getActionKey(); if
		 * (actionKey.equals("/admin/doSave")) controller.render("edit.html");
		 */
	}
}
